package com.kernel.streamDemo;

import java.io.*;

/****************************************
 * @name InputStreamDemo01
 * @description 字节输入流学习
 * @author 黄彬恒
 * @since 2018/8/17
 ***************************************/
public class InputStreamDemo01 {
    public static void main(String[] args) {
        File file = new File("D:\\ideaProgram\\IOLearning\\src\\main\\resources\\testDir\\2.txt");
        InputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(file);
            byte[] bytes = new byte[(int) file.length()]; // 数组大小由文件决定
            for (int i = 0; i < bytes.length; i++) {
                bytes[i] = (byte) fileInputStream.read(); // 读取内容
            }
            String s = new String(bytes);
            System.out.println(s);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
